// @Date         2021-11-24
// @Author       Aaron Zhang
// @Description
// @FileName      command_template.go

package template

import "zin/framework/util"

var commandTemplate = `
// @Date         {{.date}}
// @Author       Aaron Zhang
// @Description   
// @FileName      {{.name}}.go   

package {{.name}}

import (
	"fmt"
	"log"
	"zin/framework/cobra"
)

// Init
func Init{{.name|title}}Command() *cobra.Command {
	{{.name}}Command.AddCommand(sub{{.name|title}}Command)
	return {{.name}}Command
}

var {{.name}}Command = &cobra.Command{
	Use:     "{{.name}}",
	Short:   "简要说明",
	RunE: func(cmd *cobra.Command, args []string) error {
		fmt.Println("this is {{.name}}Command")
		cmd.Help()
		return nil
	},
}

var sub{{.name|title}}Command = &cobra.Command{
	Use:     "sub",
	Short:   "简要说明",
	RunE: func(c *cobra.Command, args []string) error {
		log.Println("this is {{.name}} sub command")
		return nil
	},
}
`

func CreateNewCommand(name string) error {
	commandFolder := util.GetAppProvider().CommandFolder()
	data := map[string]interface{}{
		"name":name,
	}
	return putContentToFileByTemplate(name, name, commandTemplate, commandFolder,data)
}